﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Globalization;

namespace Transportr.ServiceModel
{
    public enum VehicleType { LocalBus = 1, Tram = 2, Metro = 3, Trolley = 4, Suburban = 5, NightBus = 6, Unknown = -1 };
    
    public enum Function
    {
        StationLines = 1, Lines, LineInfo, Stations, Terms, LineTypes,
        StationSubs, StationTimetables
    };

    public struct Parameters
    {
        public double? stLat;
        public double? stLng;
        public float? dist;
        public List<int> lnId;
        public DateTime? date;
    }

    /* Objects for "func 1" */

    public class Station
    {
        [XmlAttribute]
        public int stId;
        [XmlAttribute]
        public string stName;
    }

    public class StationLine
    {
        [XmlAttribute]
        public string coName;
        [XmlAttribute]
        public int stId;
        [XmlAttribute]
        public string stName;
        [XmlAttribute]
        public double stLat;
        [XmlAttribute]
        public double stLng;
        [XmlAttribute]
        public int lnId;
        [XmlAttribute]
        public int ltId;
        [XmlAttribute]
        public string lnNumber;
        [XmlAttribute]
        public int slRoute;
        [XmlElement]
        public Station EndStations;
    }

    public class _StationLines
    {
        [XmlElement]
        public List<StationLine> StationLine;

        public _StationLines()
        {
            StationLine = new List<StationLine>();
        }
    }

    /* Objects for "func 2" */

    public class Line
    {
        [XmlAttribute]
        public int coId;
        [XmlAttribute]
        public string coName;
        [XmlAttribute]
        public int lnId;
        [XmlAttribute]
        public int ltId;
        [XmlAttribute]
        public string lnNumber;
        [XmlElement]
        public int endId1;
        [XmlElement]
        public string endName1;
        [XmlElement]
        public int endId2;
        [XmlElement]
        public string endName2;
    }

    public class _Lines
    {
        [XmlElement]
        public List<Line> Line;

        public _Lines()
        {
            Line = new List<Line>();
        }
    }

    /* Objects for "func 3" */

    public class Timetable
    {
        [XmlAttribute]
        public int teId;
        [XmlAttribute]
        public string teName;
        [XmlAttribute]
        public string teDateFrom;
        [XmlAttribute]
        public string teDateTo;
        [XmlAttribute]
        public int ttId;
        [XmlAttribute]
        public string ttDay;
        [XmlAttribute]
        public int ttHour;
        [XmlAttribute]
        public int ttFixMin;
        [XmlAttribute]
        public int ttMinMin;
        [XmlAttribute]
        public int ttMaxMin;
    }

    public class StationDetail
    {
        [XmlAttribute]
        public int lnId;
        [XmlAttribute]
        public int stId;
        [XmlAttribute]
        public string stName;
        [XmlAttribute]
        public double stLat;
        [XmlAttribute]
        public double stLng;
        [XmlAttribute]
        public int slNumber;
        [XmlAttribute]
        public int slTime;
        [XmlAttribute]
        public int slRoute;
        [XmlElement]
        public List<Timetable> Timetable;

        public StationDetail()
        {
            Timetable = new List<Timetable>();
        }
    }

    public class LineInfo
    {
        [XmlAttribute]
        public string coName;
        [XmlAttribute]
        public int lnId;
        [XmlAttribute]
        public string lnType;
        [XmlAttribute]
        public string lnNumber;
        [XmlElement("Station")]
        public List<StationDetail> Stations;

        public LineInfo()
        {
            Stations = new List<StationDetail>();
        }
    }

    /* Objects for func 4 */

    public class Stations
    {
        [XmlElement("Station")]
        public List<StationDetail> StationList;

        public Stations()
        {
            StationList = new List<StationDetail>();
        }
    }

    /* Objects for func 5 */

    public class TermDate
    {
        [XmlAttribute]
        public string teDateFrom;
        [XmlAttribute]
        public string teDateTo;
    }

    public class Term
    {
        [XmlElement]
        public int teId;
        [XmlElement]
        public string teName;
        [XmlElement]
        public List<TermDate> TermDate;

        public Term()
        {
            TermDate = new List<TermDate>();
        }
    }

    public class Terms
    {
        [XmlElement]
        public List<Term> Term;

        public Terms()
        {
            Term = new List<Term>();
        }
    }

    public class Request
    {
        public Function Function;
        public Parameters Parameters;
    }

    [XmlRoot]
    public class Response
    {
        /* Header - general response attributes */
        [XmlAttribute]
        public int code;
        [XmlAttribute]
        public string message;
        [XmlAttribute]
        public string details;

        /* Payload */
        [XmlElement("StationLines")]
        public _StationLines StationLines;
        [XmlElement("Lines")]
        public _Lines Lines;
        [XmlElement("LineInfo")]
        public LineInfo LineInfo;
        [XmlElement]
        public Terms Terms;

        public Response()
        {
            StationLines = new _StationLines();
            Lines = new _Lines();
            LineInfo = new LineInfo();
            Terms = new Terms();
        }
    }

    public class Helper
    {
        public static NumberFormatInfo NumberFormat = CultureInfo.InvariantCulture.NumberFormat;
        public static DateTimeFormatInfo DatetimeFormat = CultureInfo.InvariantCulture.DateTimeFormat;

        public static Dictionary<Function, string> Functions = new Dictionary<Function, string>()
        {
            {Function.StationLines, "StationLines"},
            {Function.Lines, "Lines"},
            {Function.LineInfo, "LineInfo"},
            {Function.Stations, "Stations"},
            {Function.Terms, "Terms"},
            {Function.LineTypes, "LineTypes"}
        };

    }
}
